//
//  FKDownloadingTableViewCellCell.m
//  FK
//
//  Created by handy wang on 6/8/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>

#import "FKDownloadingTableViewCell.h"

#define SELF_NAME_LABEL_TAG                             (1)

@interface FKDownloadingTableViewCell()

@end


@implementation FKDownloadingTableViewCell

@synthesize downloadTask = _downloadTask;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (void)setDownloadTask:(FKDownloadTask *)downloadTaskParam {
    if (_downloadTask != downloadTaskParam) {
        [_downloadTask release];
        _downloadTask = nil;
        _downloadTask = [downloadTaskParam retain];
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    UILabel *_nameLabel = (UILabel *)[self viewWithTag:SELF_NAME_LABEL_TAG];
    if (!_nameLabel) {
        CGRect _nameLabelFrame = CGRectMake(10, 0, 100, self.frame.size.height);
        _nameLabel = [[UILabel alloc] initWithFrame:_nameLabelFrame];
        _nameLabel.tag = SELF_NAME_LABEL_TAG;
        [_nameLabel setFont:[UIFont systemFontOfSize:12]];
        [_nameLabel setLineBreakMode:UILineBreakModeTailTruncation];
        [_nameLabel setNumberOfLines:1];
        [_nameLabel setTextColor:[UIColor blackColor]];
        [_nameLabel setBackgroundColor:[UIColor clearColor]];
        [self addSubview:_nameLabel];        
    }
    [_nameLabel setText:_downloadTask.name];
}

- (void)dealloc {
    [_downloadTask release];
    _downloadTask = nil;
    
    [super dealloc];
}

@end